﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;
using System.Web;
using System.Web.Script.Services;
using System.Threading;

[ServiceContract(Namespace = "", SessionMode = SessionMode.Allowed)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class ServiceRequiringSession
{
	private const String SessionKey = "ServiceRequiringSession_counter";

	[OperationContract]
	[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
	public int GetTimesSessionUsed()
	{
		var session = HttpContext.Current.Session;

		int val = 0;
		if (session[SessionKey] != null)
		{
			val = int.Parse(session[SessionKey].ToString());
		}

		session[SessionKey] = ++val;

		Thread.Sleep(1000);
		return val;
	}
}
